package logic

import (
	"context"
	"goodsrpc/goods"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseAddLogic) HouseAdd(req *types.HouseAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.Goods.HouseAdd(l.ctx, &goods.HouseAddRequest{
		Name:        req.Name,
		Price:       uint64(req.Price),
		FacePrice:   uint64(req.FacePrice),
		HouseNumber: req.HouseNumber,
		ListingTime: req.ListingTime,
		State:       req.State,
		UserId:      req.UserId,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msy:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msy:  "房源添加成功",
		Data: add,
	}, nil
}
